package com.jshongli.myapplication.task;

import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.jshongli.myapplication.R;
import com.jshongli.myapplication.base.BaseActivity;
import com.jshongli.myapplication.common.utils.AccountManager;
import com.jshongli.myapplication.common.utils.MyDialog;
import com.jshongli.myapplication.model.base.TabEntity;
import com.jshongli.myapplication.model.task.TaskBean;
import com.jshongli.myapplication.task.fragment.TaskDetailFragment;
import com.jshongli.myapplication.task.fragment.TaskEventFragment;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.ArrayList;

import butterknife.BindView;
import okhttp3.FormBody;
import okhttp3.Request;

public class TaskDetailActivity extends BaseActivity {

    public static TaskDetailActivity mActivity;

    @BindView(R.id.tb)
    CommonTabLayout tb;
    TextView tv_right;

    private String[] mTitles = {};
    private ArrayList<Fragment> mFragments = new ArrayList<>();

    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();

    TaskBean.DATA item;
    int type;


    @Override
    protected void initData() {
        super.initData();
        mActivity = this;

        item = (TaskBean.DATA)getIntent().getSerializableExtra("item");
        type = getIntent().getIntExtra("type",0);
    }

    @Override
    protected void initView() {
        super.initView();

        mToolbar.setTitle("任务详情");
        initToolbarBack(mToolbar);
        tv_right = mToolbar.getTvRight();


        if(item.status == 0 || item.status == 1 ){
            if(String.valueOf(item.userId).equals(AccountManager.getUserId()))
            {
                initTvRightText(mToolbar,"反馈",null);
            }
        }


        mTitles = new String[]{"任务详情", "代维事件"};
        mFragments.add(new TaskDetailFragment(item));
        mFragments.add(new TaskEventFragment(String.valueOf(item.id)));



        for (int i = 0; i < mTitles.length; i++) {
            mTabEntities.add(new TabEntity(mTitles[i]));
        }
        tb.setTabData(mTabEntities, this, R.id.fl, mFragments);
        tb.setCurrentTab(0);
    }


    public void getData() {
//        if(type == 0){
//            myPatrol.getData();
//            allPatrol.getData();
//        }
    }

    @Override
    protected void onTvRightClicked() {
        super.onTvRightClicked();
        Bundle bundle = new Bundle();
        bundle.putString("id",String.valueOf(item.id));
        bundle.putString("type","fk");
        openActivity(TaskReplyActivity.class,bundle,false);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_task_detail;
    }
}